package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author 赵赳
 * @createTime: 2021/2/25 0:15
 * @description:
 */
@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;


    @PostMapping(value = "/payment/creat")
    public CommonResult creat(@RequestBody Payment payment){
        int result = paymentService.creat(payment);
        log.info("~~~~~~~~~~~~~~插入数据"+result);
        if(result>0){
            return new CommonResult(200,"插入数据成功,端口号 "+serverPort,result);
        }else{
            return new CommonResult(444,"插入数据失败",null);
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Integer id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("~~~~~~~~~~~~~~查询数据"+payment);
        if(payment!=null){
            return new CommonResult<Payment>(200,"查询数据成功,端口号 "+serverPort,payment);
        }else{
            return new CommonResult<Payment>(444,"查询数据失败,查询id="+id,null);
        }
    }

}
